package main

import (
	"doudizhu/msg"
	"fmt"
	"strconv"
	"strings"
)

func main() {
	ar := msg.GetAllRooms()
	p1 := new(msg.Player)
	p2 := new(msg.Player)
	p3 := new(msg.Player)
	p1.UserId = "1"
	p2.UserId = "2"
	p3.UserId = "3"
	rid := ar.NewRoom(p1)
	ar.JoinRoom(p2, rid)
	ar.JoinRoom(p3, rid)
	room := ar.GetRoom(rid)
	p1.Ready()
	fmt.Println(room.StartGame())
	p2.Ready()
	p3.Ready()
	fmt.Println(room.StartGame())
	fmt.Println(room)
	for {
		p := room.Players[room.NextPlayer]
		fmt.Println("现有手牌：", p.ShowCards())
		var str string
		fmt.Scanln(&str)
		fmt.Println("用户", p.UserId, "准备出牌：", str)
		if str == "pass" {
			p.Pass()
			continue
		}
		csstrs := strings.Split(str, ",")
		cs := make([]msg.Card, 0, 0)
		for _, o := range csstrs {
			ns := strings.Split(o, "-")
			num, _ := strconv.Atoi(ns[0])
			types, _ := strconv.Atoi(ns[1])
			cs = append(cs, msg.Card{num, types})
		}
		fmt.Println(p.Chupai(cs))
	}
}
